package imgshare.service.impl;

import imgshare.common.api.ResultCode;
import imgshare.common.exception.ApiException;
import imgshare.mapper.CategoryMapper;
import imgshare.model.Category;
import imgshare.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> findAll() {

        return categoryMapper.selectAll();
    }

    @Override
    public void create(Category category) {

        int rowChanged = categoryMapper.insert(category);
        if (rowChanged == 0) {
            throw new ApiException(ResultCode.SQL_ERROR);
        }
    }
}
